/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package IHM;

import TouristManagement.ResponsableSite.ResponsableSite;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import java.util.Map;
import javax.swing.JOptionPane;



/**
 *
 * @author HaBL
 */
public class ResponsableSiteIHM extends javax.swing.JFrame {

    /**
     * Creates new form ResponsableSite
     */
    private ResponsableSite responsable;
    
    public ResponsableSiteIHM() {
        initComponents();
        setTitle("Responsable du site");
        responsable = new ResponsableSite();        
        init();
         
    }
    
    private void init(){

        responsable.initServer();
        Map<Short,String> mp;
        mp = responsable.getListSite();
        Cb_NomSite.addItem("...");
        for (Short i:mp.keySet()){
            Cb_NomSite.addItem(mp.get(i));   
        }
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Btn_Aff = new javax.swing.JButton();
        Lb_TitreStatSite = new javax.swing.JLabel();
        Lbl_Affluence = new javax.swing.JLabel();
        Lbl_DureeMoyen = new javax.swing.JLabel();
        Lbl_DureeMax = new javax.swing.JLabel();
        Lbl_DureeMin = new javax.swing.JLabel();
        Cb_NomSite = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        Lbl_NomSite = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setPreferredSize(new java.awt.Dimension(600, 560));
        setResizable(false);

        Btn_Aff.setText("Get statistiques du site");
        Btn_Aff.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Btn_AffActionPerformed(evt);
            }
        });

        Lb_TitreStatSite.setFont(new java.awt.Font("Aharoni", 1, 24)); // NOI18N
        Lb_TitreStatSite.setForeground(new java.awt.Color(51, 51, 51));
        Lb_TitreStatSite.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Lb_TitreStatSite.setText("Statistiques du site");

        Lbl_Affluence.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        Lbl_Affluence.setForeground(new java.awt.Color(102, 0, 0));
        Lbl_Affluence.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Lbl_Affluence.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Affluence quotidienne", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        Lbl_DureeMoyen.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        Lbl_DureeMoyen.setForeground(new java.awt.Color(102, 0, 0));
        Lbl_DureeMoyen.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Lbl_DureeMoyen.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Durée visite moyenne", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        Lbl_DureeMax.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        Lbl_DureeMax.setForeground(new java.awt.Color(102, 0, 0));
        Lbl_DureeMax.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Lbl_DureeMax.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Durée visite maximale", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        Lbl_DureeMin.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        Lbl_DureeMin.setForeground(new java.awt.Color(102, 0, 0));
        Lbl_DureeMin.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Lbl_DureeMin.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Durée visite minimal", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.ABOVE_TOP, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        jLabel1.setText("Nom du site");

        jMenu1.setText("File");

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        jMenuItem1.setText("Exit");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Aide");

        jMenuItem2.setText("About");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem2);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(Lbl_DureeMoyen, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(Lbl_DureeMax, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(0, 10, Short.MAX_VALUE)
                                .addComponent(Lbl_NomSite, javax.swing.GroupLayout.PREFERRED_SIZE, 561, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(Lb_TitreStatSite, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(Cb_NomSite, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(Btn_Aff, javax.swing.GroupLayout.DEFAULT_SIZE, 305, Short.MAX_VALUE))))
                    .addComponent(Lbl_Affluence, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(Lbl_DureeMin, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Lb_TitreStatSite)
                .addGap(4, 4, 4)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Cb_NomSite)
                    .addComponent(Btn_Aff, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addComponent(Lbl_NomSite, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Lbl_DureeMoyen, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(Lbl_DureeMax, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(Lbl_DureeMin, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(Lbl_Affluence, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(46, 46, 46))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {Lbl_Affluence, Lbl_DureeMax, Lbl_DureeMin, Lbl_DureeMoyen});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void Btn_AffActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Btn_AffActionPerformed
        if (this.Cb_NomSite.getSelectedItem().toString().equals("...")) {
            JOptionPane.showMessageDialog(this," Veuillez choisir le site à consulter","Attention",JOptionPane.WARNING_MESSAGE);

        }
        else
        {
            Map<String,String> consulLocal = responsable.consultStatLocal(((short)Cb_NomSite.getSelectedIndex()));
            Lbl_NomSite.setText("Site: "+ consulLocal.get("nameSite"));
            Lbl_DureeMoyen.setText(consulLocal.get("durationAverage")+" minutes");
            Lbl_DureeMax.setText(consulLocal.get("durationMax")+" minutes");
            Lbl_DureeMin.setText(consulLocal.get("durationMin")+" minutes");
            Lbl_Affluence.setText(consulLocal.get("affluenceQuotidienne"));
        }
    }//GEN-LAST:event_Btn_AffActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        WindowEvent winEvent= new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
        Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winEvent);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        new ZAboutIHM().setVisible(true);
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ResponsableSiteIHM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ResponsableSiteIHM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ResponsableSiteIHM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ResponsableSiteIHM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ResponsableSiteIHM().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Btn_Aff;
    private javax.swing.JComboBox Cb_NomSite;
    private javax.swing.JLabel Lb_TitreStatSite;
    private javax.swing.JLabel Lbl_Affluence;
    private javax.swing.JLabel Lbl_DureeMax;
    private javax.swing.JLabel Lbl_DureeMin;
    private javax.swing.JLabel Lbl_DureeMoyen;
    private javax.swing.JLabel Lbl_NomSite;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    // End of variables declaration//GEN-END:variables
}
